In logic and mathematics, or, also known as logical disjunction or inclusive disjunction, is a logical operator that results in true whenever one or more of its operands are true. E.g. in this context, "A or B" is true if A is true, or if B is true, or if both A and B are true. In grammar, or is a coordinating conjunction. In ordinary language "or" sometimes has the meaning of exclusive disjunction.
Contents |
Or is usually expressed with an infix operator. In mathematics and logic, it is usually ∨; in electronics, +; and in programming languages, | or or. Some programming languages have a related control structure, the short-circuit or, written ||, or else, etc.
Logical disjunction is an operation on two logical values, typically the values of two propositions, that produces a value of false if and only if both of its operands are false. More generally a disjunction is a logical formula that can have one or more literals separated only by ORs. A single literal is often considered to be a degenerate disjunction.
The truth table of p OR q is:
p | q | ∨ |
---|---|---|
T | T | T |
T | F | T |
F | T | T |
F | F | F |
The following properties apply to disjunction:
The mathematical symbol for logical disjunction varies in the literature. In addition to the word "or", the symbol "", deriving from the Latin word vel for "or", is commonly used for disjunction. For example: "A B " is read as "A or B ". Such a disjunction is false if both A and B are false. In all other cases it is true.
All of the following are disjunctions:
The corresponding operation in set theory is the set-theoretic union.
Operators corresponding to logical disjunction exist in most programming languages.
Disjunction is often used for bitwise operations. Examples:
The or
operator can be used to set bits in a bitfield to 1, by or
-ing the field with a constant field with the relevant bits set to 1.
Many languages distinguish between bitwise and logical disjunction by providing two distinct operators; in languages following C, bitwise disjunction is performed with the single pipe (|
) and logical disjunction with the double pipe (||
) operators.
Logical disjunction is usually short-circuited; that is, if the first (left) operand evaluates to true
then the second (right) operand is not evaluated. The logical disjunction operator thus usually constitutes a sequence point.
Although in most languages the type of a logical disjunction expression is boolean and thus can only have the value true
or false
, in some (such as Python and JavaScript) the logical disjunction operator returns one of its operands; the first operand if it evaluates to a true value, and the second operand otherwise.
The Curry-Howard correspondence relates a constructivist form of disjunction to tagged union types.
The union used in set theory is defined in terms of a logical disjunction: x ∈ A ∪ B if and only if (x ∈ A) ∨ (x ∈ B). Because of this, logical disjunction satisfies many of the same identities as set-theoretic union, such as associativity, commutativity, distributivity, and de Morgan's laws.
|
|
|
|